using System;
using System.Diagnostics.Metrics;
using System.IO;
using System.Net.NetworkInformation;

// 定义抽象部分的接口
public interface IAbstraction
{
    void Operation();
}

// 定义扩展抽象部分的类
public class RefinedAbstraction : IAbstraction
{
    private IImplementor _implementor;

    public RefinedAbstraction(IImplementor implementor)
    {
        _implementor = implementor;
    }

    public void Operation()
    {
        _implementor.OperationImpl();
    }
}

// 定义实现部分的接口
public interface IImplementor
{
    void OperationImpl();
}

// 定义具体实现A
public class ConcreteImplementorA : IImplementor
{
    public void OperationImpl()
    {
        Console.WriteLine("ConcreteImplementorA: Implementing operation.");
    }
}

// 定义具体实现B
public class ConcreteImplementorB : IImplementor
{
    public void OperationImpl()
    {
        Console.WriteLine("ConcreteImplementorB: Implementing operation differently.");
    }
}

// 客户端代码
public class Client
{
    public static void Main()
    {
        IAbstraction abstractionA = new RefinedAbstraction(new ConcreteImplementorA());
        abstractionA.Operation();

        Console.WriteLine("\nClient switches implementation.");

        IAbstraction abstractionB = new RefinedAbstraction(new ConcreteImplementorB());
        abstractionB.Operation();
    }
}

//输出结果：
//ConcreteImplementorA: Implementing operation.
//Client switches implementation.
//ConcreteImplementorB: Implementing operation differently.